package vn.mobiistar.videoapp.other;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

/*
 * class for holding video's information object\
 */

public class Category {
	private int id;
	private String name;
	private String description;
	private String icon;
	private int isShowInMenu;
	
	private int isFeature;

	public static ArrayList<Category> valueOf(JSONObject paramJSONObject)
			throws JSONException {
		ArrayList<Category> arrr = new ArrayList<Category>();
		JSONObject rootObject = paramJSONObject.getJSONObject("items");
        String url =  rootObject.getString("imageUrl");
        
        for (int i = 0; i < rootObject.length()-1; i++) {
        	JSONObject item = rootObject.getJSONObject(String.valueOf(i));
				Category v = new Category();
				if (item.getString("id") != null && item.getString("id") != "")
					v.setId(item.getInt("id"));
				if (item.getString("description") != null
						&& item.getString("description") != "null")
					v.setDescription(item.getString("description"));
				if (item.getString("name") != null && item.getString("name") != "")
					v.setName(item.getString("name"));
				if (item.getString("is_showinslide") != null && item.getString("is_showinslide") != "")
					v.setIsShowMenu(item.getInt("is_showinslide"));
				if (item.getString("is_feature") != null && item.getString("is_feature") != "")
					v.setIsFeature(item.getInt("is_feature"));
				
				if(item.getString("icon") != null && item.getString("icon") != ""  ) v.setIcon(url+item.getString("icon"));
				arrr.add(v);
		}
		
		Log.v("category", arrr.size() + " loaded");
		return arrr;
	}
	
	
	// setter getter
	public void setIsFeature(int isFeature) {
		this.isFeature = isFeature;
	}
	public int getIsFeature() {
		return isFeature;
	}
	private void setIsShowMenu(int isShow) {
		this.isShowInMenu = isShow;
		
	}
	public String getIcon() {
		return icon;
	}
	public void setIcon(String icon) {
		this.icon = icon;
	}
	public void setId(int id) {
		this.id = id;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public int getId() {
		return id;
	}
	public String getName() {
		return name;
	}
	
	public int getIsShowInMenu() {
		return isShowInMenu;
	}
}
